# -*- coding: utf-8 -*-

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from board.models import *



class BoardAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('subject',)}
    list_display = ('subject', 'slug', 'show_moderators', 'internal',
                    'guest_post', 'display_position')
    list_display_links = ('subject',)
    list_editable = ('internal', 'guest_post', 'display_position')

    def show_moderators(self, obj):
        mods = obj.moderators.all()
        return u', '.join([x.username for x in mods])


class PostAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('subject',)}

    def save_model(self, req, obj, form, change):
        obj.save()
        hist = PostHistory(post=obj, user=req.user)
        if obj.editors.all().count() == 0:
            hist.reason = _(u'Author')
        hist.save()


admin.site.register(Tag)
admin.site.register(Board, BoardAdmin)
admin.site.register(Post, PostAdmin)
admin.site.register(PostHistory)

